﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MinhTam.DataAccess.Web;
using MinhTam.Objects;

public partial class banggiave : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadpricetable();

        }
    }
    public void loadpricetable()
    {
        try
        {
            string sqlBG = @"select top 1 bgx.mo_ta,bgx.BANG_GIA_XE_ID FROM BANG_GIA_XE bgx
             where dang_ap_dung='Y'";
            DataTable dtBG = SQLConnectWeb.GetTable(sqlBG);
            if (dtBG != null && dtBG.Rows.Count > 0)
            {
                lblMoTa.Text = dtBG.Rows[0][BANG_GIA_XE.cl_MO_TA].ToString();

                string sql = string.Format(@"SELECT td.BEN_DI,td.BEN_DEN,td.TUYEN_DUONG_ID, {0} BANG_XE_GIA_ID 
                FROM TUYEN_DUONG td
                WHERE EXISTS(SELECT TOP 1 bgxc.BANG_GIA_XE_CT_ID
                               FROM BANG_GIA_XE_CT bgxc WHERE td.TUYEN_DUONG_ID=bgxc.TUYEN_DUONG_ID and bgxc.BANG_GIA_XE_ID={0})
                ORDER BY td.BEN_DI,td.BEN_DEN", dtBG.Rows[0][BANG_GIA_XE.cl_BANG_GIA_XE_ID]);
                DataTable dt = SQLConnectWeb.GetTable(sql);

                list.DataSource = dt;
                list.DataBind();
            }
        }
        catch
        {
        }
    }
    protected void list_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView view = e.Item.DataItem as DataRowView;
        GridView grid = e.Item.FindControl("gridViewData") as GridView;
        if (grid != null)
        {
            string sql = string.Format(@"SELECT ROW_NUMBER() OVER (ORDER BY  bgxc.BEN_DI,bgxc.BEN_DEN, lx.TEN_LOAI) STT,
            bgxc.*,
            lx.TEN_LOAI TEN_LOAI_XE
            FROM BANG_GIA_XE_CT bgxc
            LEFT JOIN LOAI_XE lx ON lx.LOAI_XE_ID=bgxc.LOAI_XE_ID where bgxc.TUYEN_DUONG_ID={0} and bgxc.BANG_GIA_XE_ID={1}", view[TUYEN_DUONG.cl_TUYEN_DUONG_ID], view["BANG_XE_GIA_ID"].ToString());
                        DataTable dt=SQLConnectWeb.GetTable(sql);
            grid.DataSource = dt;
            grid.DataBind();

        }
    }
}